<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var minimumTimeRequired = function (jobs, k) {
      jobs.sort((a, b) => b - a)
      let l = jobs[0], r = jobs.reduce((a, c) => a + c), mid, works = new Array(k),
        f = (i, m) => {
          if (i === jobs.length) return true
          for (let j = 0; j < works.length; j++) {
            if (jobs[i] + works[j] <= m) {
              works[j] += jobs[i]
              if (f(i + 1, m)) return true
              works[j] -= jobs[i]
            }
            if (works[j] === 0 || jobs[i] + works[j] === m) break
          }
          return false
        }
      while (l < r) {
        mid = l + r >> 1
        works = works.fill(0)
        f(0, mid) ? r = mid : l = mid + 1
      }
      return r
    };
  </script>

</body>

</html>